module.exports = function(success,error){
    //判断
    if(typeof error !== 'function'){
        error = () => {
            console.log('连接失败~~~');
        }
    }
    //安装npm i mongoose
    const mongoose = require('mongoose');
    //导入配置文件---config
    const {DBHOST,DBPORT,DBNAME} = require('../config/config.js');

    //设置strictQuery 为true
    mongoose.set('strictQuery',true);

    //连接mongodb服务
    mongoose.connect(`mongodb://${DBHOST}:${DBPORT}/${DBNAME}`);


    //设置回调
    mongoose.connection.once('open', () => {
        success();
    });//设置连接成功的回调
    mongoose.connection.once('error', () => {
        error();
    
    });//设置连接错误的回调
    mongoose.connection.on('close', () => {
    console.log('连接关闭');
    });//设置连接关闭的回调
}